import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;


public class BriberTest {
	
	Briber fred;

	@Before
	public void setUp() throws Exception {
		fred = new Briber("Fred", "Flintstone", 10);
	}

	@Test
	public void constructor() {
		String name = fred.getFirstName();
		assertTrue(name.equals("Fred"));
		
		name = fred.getLastName();
		assertTrue(name.equals("Flintstone"));
		
		int initialBribe = fred.getBribe();
		assertTrue(initialBribe == 10);
		
		Briber other = new Briber("First", "Last", 20);
		name = other.getFirstName();
		assertTrue(name.equals("First"));
		
		name = other.getLastName();
		assertTrue(name.equals("Last"));

		
		initialBribe = other.getBribe();
		assertTrue(initialBribe == 20);
	}
	
	@Test
	public void addToBribe() {
		assertTrue(fred.getBribe() == 10);
		
		fred.addToBribe(20);
		int totalBribe = fred.getBribe();
		assertTrue(totalBribe == 10 + 20);
		
		fred.addToBribe(30);
		totalBribe = fred.getBribe();
		assertTrue(totalBribe == 10 + 20 + 30);
	}
	
	@Test
	public void noNegativeBribes() {
		assertTrue(fred.getBribe() == 10);

		fred.addToBribe(-5);
		
		assertTrue(fred.getBribe() == 10);
	}
	
	@Test
	public void equalsTotalMatch() {
		Briber other = new Briber("Fred", "Flintstone", 0);
		
		assertTrue(other.equals(fred) == true);
	}
	
	@Test
	public void notEqualTotalUnMatch() {
		Briber other = new Briber("Joe", "Nobody", 10);
		
		assertTrue(other.equals(fred) == false);		
	}
	
	@Test
	public void notEqualFirstOrLast() {
		Briber differentFirstSameLast = new Briber("Wilma", "Flintstone", 0);		
		assertTrue(differentFirstSameLast.equals(fred) == false);
		
		Briber sameFirstDifferentLast = new Briber("Fred", "Savage", 0);
		assertTrue(sameFirstDifferentLast.equals(fred) == false);
		
	}
	
	@Test
	public void compareToOnlyBribe() {
		Briber small = new Briber("Ziggy", "Zigstone", 20);
		Briber big = new Briber("Albert", "Albertson", 500);
		
		int difference = small.compareTo(big);
		assertTrue(difference == 20 - 500);
		
		difference = big.compareTo(small);
		assertTrue(difference == 500 - 20);
	}
	
	@Test
	public void compareToBribesMatchDifferentFirstNames() {
		Briber bigName = new Briber("Ziggy", "Zigstone", 500);
		Briber smallName = new Briber("Albert", "Albertson", 500);
		
		assertTrue(smallName.compareTo(bigName) < 0);
		assertTrue(bigName.compareTo(smallName) > 0);		
	}
	
	@Test
	public void compareToBribesAndFirstNameMatchSoLastName() {
		Briber bigName = new Briber("Ziggy", "Zigstone", 500);
		Briber smallName = new Briber("Ziggy", "Albertson", 500);
		
		assertTrue(smallName.compareTo(bigName) < 0);		
		assertTrue(bigName.compareTo(smallName) > 0);
	}

}
